<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>无缝滚动</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            position: relative;
            margin: 50px auto;
            width: 600px;
            height: 200px;
            border: 1px solid #000000;
            overflow: hidden;
        }

        .box>ul {
            position: absolute;
            top: 0;
            left: 0;
            width: 300%;
            height: 100%;
            list-style: none;
        }

        .box>ul>li {
            float: left;
        }

        .box>ul>li>img {
            /* 去除垂直方向空隙 */
            vertical-align: top;
        }
    </style>

    <script>
        window.onload = function () {
            function $(selecter) {
                return document.querySelector(selecter)
            }
            var moveVal = 0
            var timer = null
            function fn ()  {
                moveVal -= 3
                if(moveVal<=-4 * 300){
                    moveVal=0
                }
                $('ul').style.left = moveVal + 'px'
            }
            timer = setInterval(fn, 30)

            //鼠标放到大盒子上，动画停止
            $('.box').onmouseover=function(){
                clearInterval(timer)
            }
            // 鼠标离开大盒子，开启定时器
            $('.box').onmouseout=function(){
                timer = setInterval(fn, 30)
            }

        }
    </script>
</head>

<body>
    <div class="box">
        <ul>
            <li><img src="./01.jpg" alt="图片"></li>
            <li><img src="./02.jpg" alt="图片"></li>
            <li><img src="./03.jpg" alt="图片"></li>
            <li><img src="./04.jpg" alt="图片"></li>
            <!-- 利用人眼视觉停留 -->
            <li><img src="./01.jpg" alt="图片"></li>
            <li><img src="./02.jpg" alt="图片"></li>
        </ul>
    </div>
</body>

</html>